package com.nuit.cxl.bilibili.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.nuit.cxl.bilibili.service.RecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.core.io.ResourceLoader;

import javax.sql.DataSource;

//1.在这个配置类上面 加上@Configuration这个注解,
//2.在我们的JavaConfig里面的直接加上@Import(JdbcConfig.class)这个注解
//@Configuration
public class JdbcConfig {
    @Value("${jdbc.userName}")
    private String userName;
    @Value("${jdbc.password}")
    private String password;
    @Autowired
    private RecommendService recommendService1;

    //1 在配置类里面写一个get的方法
    //2 添加@Bean的注解 代表他返回的是一个Bean
    @Bean
    public DataSource getDataSource(RecommendService recommendService) {
        System.out.println(recommendService1);
        System.out.println(recommendService);
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test");
        dataSource.setUsername(userName);
        dataSource.setPassword(password);
        return dataSource;
    }
}
